<!--
* @description 我的未完成任务
* @author zywu
* @date 2021/03/19 15:54:03
!-->
<template>
  <div class="inspect-uncomplete">
    <div class="inspect-uncomplete__head">未完成任务</div>

    <van-list
      v-model="loading"
      :finished="finished"
      :finished-text="taskList.length>0?'暂无更多':''"
      @load="getTaskList(false)"
    >
      <div class="inspectList_cell" v-for="(item) in taskList" :key="item.id">
        <inspect-module :data-obj="item" :showBtn="false" stamp readonly></inspect-module>
      </div>
    </van-list>
    <div v-if="taskList.length==0" class="no-data-img">
      <img src="../../assets/img/common/defaultnone.png" />
    </div>
  </div>
</template>

<script>
import InspectModule from './InspectModule.vue'
import { getExamineTaskListByPage } from '@/api/inspect'
export default {
  components: { InspectModule },
  props: {
    params: {
      type: Object,
      default: function () {
        return {}
      },
    },
    watchParams: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      taskList: [],
      pageIndex: 0,
      loading: false,
      finished: false,
    }
  },

  computed: {},

  watch: {
    params() {
      if (this.watchParams) this.getTaskList()
    },
  },

  created() {},

  mounted() {},

  methods: {
    getTaskList(isRefresh = true) {
      if (isRefresh) {
        this.pageIndex = 0
        this.taskList = []
        this.finished = false
      }
      this.loading = true
      getExamineTaskListByPage({
        ...this.params,
        pageIndex: this.pageIndex,
      })
        .then((res) => {
          this.taskList = this.taskList.concat(res.data)
          // 加载状态结束
          this.loading = false
          // 数据全部加载完成
          if (this.taskList.length >= res.total) {
            this.finished = true
          } else {
            this.pageIndex++
          }
        })
        .catch((res) => {
          this.loading = false
        })
    },
  },
}
</script>
<style lang='scss'>
.inspect-uncomplete {
  padding-bottom: 10px;
  &__head {
    padding: 20px 0 10px;
    font-size: 17px;
    color: #333;
    font-weight: 500;
  }
}
</style>